package com.thon.service.project.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thon.dao.project.PreferentialDao;
import com.thon.dao.util.Page;
import com.thon.entity.project.Preferential;
import com.thon.service.project.PreferentialService;

@Service
@Transactional
public class PreferentialServiceImpl implements PreferentialService {

	@Autowired
	private PreferentialDao preferentialDao;
	@Override
	public Boolean addPreferential(Preferential preferential) {
		
		if(preferential==null)
			return false;
		if(preferential.getId()==null)
		{preferential.setCreatedDate(new Date());
		preferential.setStatus(0);
		preferential.setCommentCount(0);
		preferential.setShareCount(0);
		preferentialDao.save(preferential);}
		else
			{Preferential old = preferentialDao.get(preferential.getId());
			
			preferential.setCommentCount(old.getCommentCount());
			preferential.setShareCount(old.getShareCount());
			preferential.setCreatedDate(old.getCreatedDate());
			
			preferentialDao.update(preferential);}
		return true;
	}

	@Override
	public Boolean updatePreferential(Preferential preferential) {
		
		if(preferential==null||preferential.getId()==null)
			return false;
		 Preferential  oldPreferential = preferentialDao.get(preferential.getId());
		    oldPreferential.setStatus(preferential.getStatus());
		    oldPreferential.setTags(preferential.getTags());
		    oldPreferential.setProjectCategory(preferential.getProjectCategory());
			preferentialDao.update(oldPreferential);
			return true;
	}

	@Override
	public void deletePreferential(Integer id) {
		// TODO Auto-generated method stub

	}

	@Override
	public Preferential getPreferential(int userId, int PreferentialId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Preferential getPreferential(int PreferentialId) {		
		return preferentialDao.get(PreferentialId);
	}

	@Override
	public Page<Preferential> findAllPreferential(int status, Integer userId,
			int pageNo, int pageSize, String querySt) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Preferential> listPreferentialByStatus(int status) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Preferential> listPreferentialsBy() {
		
		return preferentialDao.listPreferential();
	}

	@Override
	public Page<Preferential> findPreferentials(int userId, Integer status,
			int pageNo, int pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<Preferential> findPreferentialByAction(int userId,
			String action, int status, int pageNo, int pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<Preferential> findPreferentialSort(String by, int pageNo,
			int pageSize, int userId, int status) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<Preferential> findPreferentialByCategory(int categoryId,
			int pageNo, int pageSize, int userId, int status) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<Preferential> findPreferentialByRegion(int pageNo,
			int pageSize, int regionId, int status) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Long countPreferential(String by, int status) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<Preferential> findPreferentialByTags(int pageNo, int pageSize,
			String tags, int userId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Preferential getPreferentialByInst(int institutionId, int status) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Preferential> listPreferentialsByStatus(int institutionId,
			int status) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Long countPreferentialByStatus(int institutionId, int status) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Long countPreferentialByCategory(int categoryId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Preferential> listAllPreferentialName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<Preferential> findPreferentialByCategory(
			Page<Preferential> page, int categoryId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<Preferential> findPreferentialByBenefit(
			Page<Preferential> page, int benefitId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<Preferential> findPreferentialByOpen(Page<Preferential> page,
			int openId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<Integer, Integer> countCategoryAmount(
			Map<Integer, Integer> newCategoryAmount) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<Preferential> listPreferential(int pageNo, int pageSize, int status, int projectCategoryId,int userId,String tags) {
		Page<Preferential> page = new Page<Preferential>();	
		page.setPageSize(pageSize);
		page.setPageNo(pageNo);			
		return preferentialDao.listPreferential(page,status,projectCategoryId,userId,tags);
	}

	

}
